import java.awt.*;
import java.util.*;

/**
 * Centipede direction, length and its segments
 * 
 * @author  James Wilkinson <jhwilkin@purdue.edu>
 * @version 1.7
 * @since   2011-11-20
 **/
public class Centipede
{
  
    public Point segments[];
    public int horizontal;
    public int vertical;
    public int length;
    
    /**
     * @param inLength     Length of the centipede to create
     * @param inHorizontal Initial horizontal heading of the centipede head
     * @param inVertical   Initial vertical heading of the centipede head
     **/
    public Centipede(int inLength, int inHorizontal, int inVertical)
    {
      
      //Initialize length, horizontal and vertical with
      //passed parameters.
      segments = new Point[inLength];
      length = inLength;
      horizontal = inHorizontal;
      vertical = inVertical;
      
      //Create all segments, assuming this is the starting centipede
      for(int i = 0; i < segments.length; i++){
        segments[i] = new Point(Settings.centipedeStartSize - i, 0);
      }
    }
    
    /**
     * Returns the segment that matches that Point.
     * 
     * @param testLoc Grid location
     * @return int corresponding to the segment that is at <code>testLoc</code> location. -1 if none match
     */
    public int contains(Point testLoc)
    {
      
      //Find the segment that contains the Point testLoc and return
      //the int corresponding to that segment.  -1 if no match.
      for(int i = 0; i < segments.length; i++){
        if(segments[i] != null && testLoc.equals(segments[i])){
           return i;
        }
      }
      
      return -1;
    }
}
